#include <iostream>
#include <functional>
using namespace std;
int main() {
  int x = 1, y = 2;
  auto lambda = [x, &y](int z) {
    ++y;
    return x;
  };
  cout << "lambda type: " << typeid(lambda).name() << endl;

  function<int(int)> functional = [x, &y](int z) {
    ++y;
    return x;
  };
  cout << "functional type: " << typeid(functional).name() << endl;

  // 使用捕获，就无法转成函数指针
  int (*pointer)(int) = [](int z) {
    return z;
  };
  cout << "pointer type: " << typeid(pointer).name() << endl;

  class Functor {
    int x;
    int &y;
   public:
    Functor(int _x, int &_y): x(_x), y(_y) {}
    int operator()(int z) {
      ++y;
      return x + y + z;
    }
  }functor(x, y);
  cout << "functor type: " << typeid(functor).name() << endl;
  cout << "通过这段代码，可以知道 lambda 的类型就是 Functor，而不是 functional 和 pointer" << endl;
}